<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video autoplay controls :src="this.url"></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="icon" alt />
          </div>
          <span class="name">{{mvInfo.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{mvInfo.name}}</h2>
          <span class="date">发布：2014-11-04</span>
          <span class="number">播放：{{mvInfo.playCount}}</span>
          <p class="desc">{{mvInfo.desc}}</p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">
          精彩评论
          <span class="number">({{hotComments.length}})</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,i) in hotComments" :key="i">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length!=0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">
          最新评论
          <span class="number">({{total}})</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,i) in comments" :key="i">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length!=0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="10"
        :limit="limit"
      ></el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" v-for="(item,i) in simiMvs" :key="i" @click="playSimivideo(item.id)">
            <div class="img-wrap">
              <img :src="item.cover" alt />
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount}}</div>
              </div>
              <span class="time">{{item.duration}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import {getMvUrl,getSimiMv,getMvDetail,getArtists,getMvComment} from '../network/mv'
export default {
  name: "mv",
  data() {
    return {
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      limit: 10,
      // mv地址
      url: "",
      // 相关mv
      simiMvs: [],
      // mv信息
      mvInfo: {},
      // 头像
      icon: "",
      // 热评
      hotComments: [],
      // 评论
      comments: [],
    };
  },
  methods: {
    handleCurrentChange(val) {
      this.page = val;

      // axios({
      //   url: "https://autumnfish.cn/comment/mv",
      //   method: "get",
      //   params: {
      //     id: this.$route.query.q,
      //     limit: 10,
      //     offset: (this.page - 1) * 10,
      //   },
      // }).then((res) => {
      //   this.hotComments = res.data.hotComments;
      //   this.comments = res.data.comments;
      //   this.total = res.data.total;
      // });
      getMvComment(this.$route.query.q,10,(this.page - 1) * 10).then(res=>{
         this.hotComments = res.data.hotComments;
        this.comments = res.data.comments;
        this.total = res.data.total;
      })
    },
    playSimivideo(id) {
        //  播放相似歌曲
        // axios.get("https://autumnfish.cn/mv/url", {
        //   params: { id: id },
        // })
        // .then((res) => {
        //   this.url = res.data.data.url;
        // });
        getMvUrl(id).then(res=>{
           this.url = res.data.data.url;
        })

      // 获取相似mv信息
     
        // axios.get("https://autumnfish.cn/mv/detail", {
        //   params: { mvid: id },
        // })
        // .then((res) => {
        //   this.mvInfo = res.data.data;
        //   // 获取歌手信息
          
        //     axios.get("https://autumnfish.cn/artists", {
        //       params: { id: this.mvInfo.artists[0].id },
        //     })
        //     .then((res) => {
        //       this.icon = res.data.artist.picUrl;
        //     });
        // });
    //     getMvDetail(id).then(res=>{
    //   this.mvInfo = res.data.data;
    //   getArtists(this.mvInfo.artists[0].id).then(res=>{
    //      this.icon = res.data.artist.picUrl;
    //   })
    // })
      // 获取相似mv评论
      
        axios.get("https://autumnfish.cn/comment/mv", {
          params: { id: id, limit: 10, offset: 0 },
        })
        .then((res) => {
          this.hotComments = res.data.hotComments;
          this.comments = res.data.comments;
          this.total = res.data.total;
        });
    },
  },
  created() {
    // 获取mv地址
    // axios({
    //   url: "https://autumnfish.cn/mv/url",
    //   method: "get",
    //   params: { id: this.$route.query.q },
    // }).then((res) => {
    //   // console.log(res);
    //   this.url = res.data.data.url;
    // });
    getMvUrl(this.$route.query.q).then(res=>{
       console.log(res);
      this.url = res.data.data.url;
    })

    // 获取相关mv
    axios({
      url: "https://autumnfish.cn/simi/mv",
      method: "get",
      params: { mvid: this.$route.query.q },
    }).then((res) => {
      // console.log(res);
      this.simiMvs = res.data.mvs;
    });
    // getSimiMv(this.$route.query.q).then(res=>{
    //    console.log(res);
    //   this.simiMvs = res.data.mvs;
    // })

    // 获取mv信息
    // axios({
    //   url: "https://autumnfish.cn/mv/detail",
    //   method: "get",
    //   params: { mvid: this.$route.query.q },
    // }).then((res) => {
    //   // console.log(res);
    //   this.mvInfo = res.data.data;
    //   // 获取歌手信息
    //   axios({
    //     url: "https://autumnfish.cn/artists",
    //     method: "get",
    //     params: { id: this.mvInfo.artists[0].id },
    //   }).then((res) => {
    //     // console.log(res);
    //     this.icon = res.data.artist.picUrl;
    //   });
    // });
    getMvDetail(this.$route.query.q).then(res=>{
      this.mvInfo = res.data.data;
      getArtists(this.mvInfo.artists[0].id).then(res=>{
         this.icon = res.data.artist.picUrl;
      })
    })

    // 获取评论数据
    // axios({
    //   url: "https://autumnfish.cn/comment/mv",
    //   method: "get",
    //   params: { id: this.$route.query.q, limit: 10, offset: 0 },
    // }).then((res) => {
    //   console.log(res);
    //   this.hotComments = res.data.hotComments;
    //   this.comments = res.data.comments;
    //   this.total = res.data.total;
    // });
    getMvComment(this.$route.query.q,10,0).then(res=>{
       this.hotComments = res.data.hotComments;
      this.comments = res.data.comments;
      this.total = res.data.total;
    })
  },
};
</script>

<style></style>
